﻿using System;
using System.Collections.Generic;
using System.Web;
using PayRoller.Code;
using System.Web.SessionState;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using HySoft.Cash.Business;
using HySoft.Cash.Structure;
using System.Configuration;
using System.Web.Profile;

namespace PayRoller.Manage.RuleSet
{
    public class RuleEdit : ParentPage, IRequiresSessionState
    {
        // Fields
        protected Button bnSave;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        public int Sid;
        protected TextBox txtRulename;

        // Methods
        protected void bnSave_Click(object sender, EventArgs e)
        {
            TsysruleBN ebn = new TsysruleBN(this.Page);
            TsysruleDT detail = ebn.Get(Convert.ToInt32(base.Request["Sid"]));
            detail.Name = this.txtRulename.Text;
            if (ebn.Edit(detail))
            {
                ebn.Close();
                ebn.Dispose();
                base.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>alert('Success!');window.location='RuleList.aspx';</script>");
            }
        }

        public void GetRuleInfo(int Sid)
        {
            TsysruleBN ebn = new TsysruleBN(this.Page);
            TsysruleDT edt = ebn.Get(Sid);
            this.txtRulename.Text = edt.Name;
            ebn.Close();
            ebn.Dispose();
        }

        protected override void OnInit(EventArgs e)
        {
            base.m_ModuleCode = "0011";
            base.CheckLogin(true);
            base.CheckPerm();
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.bnSave.Attributes.Add("onclick", "return Check1();");
            if (!this.Page.IsPostBack && (base.Request["Sid"] != null))
            {
                this.Sid = Convert.ToInt32(base.Request["Sid"]);
                this.GetRuleInfo(this.Sid);
            }
        }

        // Properties
        protected HttpApplication ApplicationInstance
        {
            get
            {
                return this.Context.ApplicationInstance;
            }
        }

        protected DefaultProfile Profile
        {
            get
            {
                return (DefaultProfile)this.Context.Profile;
            }
        }
    }

}
